import Data.Char

strToDigits :: String -> [Int]
strToDigits str = map digitToInt str

superDigit :: [Int] -> Int
superDigit [] = 0
superDigit [x] = x
superDigit xs = superDigit $ strToDigits $ show $ foldl1 (+) xs

main = do 
    l <- getLine
    let ws = words l
        a = head ws
        b = last ws
        x = superDigit $ strToDigits a
        ys = replicate (read b) x
    print $ superDigit ys